package com.hunter.sign.common.util.biometrics;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class CFingerUtils {
	
	public static double match(String imgPath1, String imgPath2){
		CFingerPrint m_finger1;
		double finger1[];
		double finger2[];
		try {
			m_finger1 = new CFingerPrint();
			CFingerPrint m_finger2 = new CFingerPrint();
//		CFingerPrintGraphics m_fingergfx = new CFingerPrintGraphics();
			BufferedImage m_bimage1 = new BufferedImage(m_finger1.FP_IMAGE_WIDTH ,m_finger1.FP_IMAGE_HEIGHT,BufferedImage.TYPE_INT_RGB);
			BufferedImage m_bimage2 = new BufferedImage(m_finger2.FP_IMAGE_WIDTH ,m_finger2.FP_IMAGE_HEIGHT,BufferedImage.TYPE_INT_RGB);
			finger1 = new double[m_finger1.FP_TEMPLATE_MAX_SIZE];
			finger2 = new double[m_finger2.FP_TEMPLATE_MAX_SIZE];
			//picture1
			//Set picture new
			m_bimage1=ImageIO.read(new File(imgPath1)) ;
			
//            FileInputStream in = new FileInputStream(new File(imgPath1));  
//            Image TheImage = BmpReader.read(in);  
//            int wideth = TheImage.getWidth(null);  
//            int height = TheImage.getHeight(null);   
//            m_bimage1.getGraphics().drawImage(TheImage, 0, 0, wideth, height, null); 
            
            
			//Send image for skeletinization
			m_finger1.setFingerPrintImage(m_bimage1) ;
			finger1=m_finger1.getFingerPrintTemplate();
			 //See what skeletinized image looks like
//	    m_bimage1 = m_finger1.getFingerPrintImageDetail();
			    
			//picture2
			//Set picture new
			m_bimage2=ImageIO.read(new File(imgPath2)) ;
			//Send image for skeletinization
			m_finger2.setFingerPrintImage(m_bimage2) ;
			finger2=m_finger2.getFingerPrintTemplate();
			//See what skeletinized image looks like
//	    m_bimage2 = m_finger2.getFingerPrintImageDetail();
		    return m_finger1.Match(finger1 , finger2, 65, false);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return 0;
		}
	}
	
	public static void main(String[] args) throws IOException {
		System.out.println(match("E:\\workspace_current\\JavaBiometric\\a.bmp", "E:\\workspace_current\\JavaBiometric\\b.bmp"));
	}
}

